import http from './http'

export function createOrder(data) {
  return http.post('/order/create', data)
}

export function getOrderDetail(orderNo) {
  return http.get(`/order/detail/${orderNo}`)
}

export function listOrders(params) {
  return http.get('/order/list', { params })
}

export function cancelOrder(data) {
  // 确保传递给后端的参数是正确的格式
  // 创建一个新的对象，只包含我们想要发送的字段
  const requestData = {
    orderNo: data.orderNo || '', // 确保有orderNo字段
    cancelReason: data.cancelReason || '用户主动取消' // 确保有cancelReason字段
  }
  
  // 这里添加日志来调试参数转换
  console.log('发送给后端的取消订单参数:', requestData)
  
  return http.post('/order/cancel', requestData)
}

export function applyRefund(data) {
  return http.post('/order/refund/apply', data)
}

export function refundStatus(refundNo) {
  return http.get('/order/refund/status', { params: { refundNo } })
}


